<%@ page language="java"
         contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"
         import="com.shxt.hotel.background.*"
         import="java.util.Map"
         import="java.util.List"
         import="com.shxt.hotel.util.Time"
%>
<%
    Staff staff = new Staff();
    
    if(session.getAttribute("staff_id") == null){
        response.sendRedirect("./login.jsp");
    }else{
        // get current Staff
        request.setCharacterEncoding("UTF-8");
        int staff_id = (int)session.getAttribute("staff_id");
        
        Map<String, Object> currentStaff = staff.getStaffInfo(staff_id).get(0);

        int sub_id = Integer.parseInt(request.getParameter("id"));
        
        Room room = new Room();
        User user = new User();
        Consume consumeManager = new Consume();
        
        
        // sub info 
        Map<String, Object> subInfo = room.getSubInfo(sub_id);
        Map<String, Object> subUser = user.getUserInfo((int)subInfo.get("uid"));
        Map<String, Object> subRoom = room.getRoom((int)subInfo.get("rid"));
        Map<String, Object> cate = room.getCategory((int)subRoom.get("category"));
        Map<String, Object> userPerm = user.getPermission((int)subUser.get("user_permission"));
        
        double totalCost = 0;
        double room_dis = (int)userPerm.get("room_discount");
        double consume_dis = (int)userPerm.get("consume_discount");
%>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="Mosaddek">
    <link rel="shortcut icon" href="../Public/img/favicon.html">

    <title>Check-out</title>

    <!-- Bootstrap core CSS -->
    <link href="../Public/css/bootstrap.min.css" rel="stylesheet">
    <link href="../Public/css/bootstrap-reset.css" rel="stylesheet">
    <!--external css-->
    <link href="../Public/assets/font-awesome/css/font-awesome.css" rel="stylesheet" />
    <!-- Custom styles for this template -->
    <link href="../Public/css/style.css" rel="stylesheet">
    <link href="../Public/css/style-responsive.css" rel="stylesheet" />

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 tooltipss and media queries -->
    <!--[if lt IE 9]>
      <script src="../Public/js/html5shiv.js"></script>
      <script src="../Public/js/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>

  <section id="container" class="">
      <!--header start-->
      <jsp:include page="./Public/header.jsp" flush="true"/>
      <!--header end-->
      <!--sidebar start-->
      <jsp:include page="./Public/sidebar.jsp" flush="true"/>
      <!--sidebar end-->
      <!--main content start-->
      <section id="main-content">
          <section class="wrapper">
              <!-- invoice start-->
              <section>
                  <div class="panel panel-primary">
                      <!--<div class="panel-heading navyblue"> INVOICE</div>-->
                      <div class="panel-body">
                          <div class="row invoice-list">
                              <div class="text-center corporate-id">
                                  <h1>Room Check-out</h1>
                              </div>
                              <!-- user info -->
                              <div class="col-lg-4 col-sm-4">
                                  <h4>USER INFO</h4>
                                  <ul class="unstyled">
                                      <li>User ID		: <span class="text-primary"><%=subUser.get("username") %></span></li>
                                      <li>Card ID		: <%=subUser.get("id_card") %> </li>
                                      <li>Phone			: <%=subUser.get("phone") %></li>
                                  </ul>
                              </div>
                              <div class="col-lg-4 col-sm-4">
                                  <h4>HOTEL INFO</h4>
                                  <p>
                                      HOTEL<br>
                                      Road 1, House 2, Sector 3<br>
                                      ABC, Dreamland 1230<br>
                                      P: +38 (123) 456-7890<br>
                                  </p>
                              </div>
                              <div class="col-lg-4 col-sm-4">
                                  <h4>INVOICE INFO</h4>
                                  <ul class="unstyled">
                                      <li>Invoice Number		: <strong><%=subInfo.get("id") %></strong></li>
                                      <li>Invoice Date		: <%=Time.getDate() %></li>
                                      <li>Due Date			: <%=Time.getDate() %></li>
                                      <li>Invoice Status		: Paid</li>
                                  </ul>
                              </div>
                          </div>
                          <table class="table table-striped table-hover">
                              <thead>
                              <tr>
                                  <th>#</th>
                                  <th>Item</th>
                                  <th class="hidden-phone">Description</th>
                                  <th class="">Unit Cost</th>
                                  <th class="">Quantity</th>
                                  <th>Total</th>
                              </tr>
                              </thead>
                              <tbody>
                              <%
                                  double dis_price = (float)cate.get("price") * (int)userPerm.get("room_discount");
                              %>
                              <tr>
                                  <td>1</td>
                                  <td><%=cate.get("title") %></td>
                                  <td class="hidden-phone"><%=cate.get("intro") %></td>
                                  <td class="">$ <%=String.format("%.2f", dis_price) %></td>
                                  <td class="">1</td>
                                  <td>$ <%=subInfo.get("deposit") %></td>
                              </tr>
                              <%
                                  List<Map<String, Object>> consumeInfoList = consumeManager.getConsumeInfoListByUserId((int)subUser.get("id"));
                                  for(Map<String, Object> consumeInfo : consumeInfoList){
                                      Map<String, Object> consumeRec = consumeManager.getConsume((int)consumeInfo.get("cid"));
                                      Map<String, Object> consumeCate = consumeManager.getConsumeCategoryByCategoryId((int)consumeRec.get("category"));
                                      totalCost += (float)consumeInfo.get("deposit") / (1 - consume_dis / 100);
                              %>
                              <tr>
                                  <td><%=consumeRec.get("id") %></td>
                                  <td><%=consumeCate.get("title") %></td>
                                  <td><%=consumeRec.get("title") %></td>
                                  <td class="">$ <%=consumeRec.get("price") %></td>
                                  <td class=""><%=consumeInfo.get("num") %></td>
                                  <td>$ <%=consumeInfo.get("deposit") %></td>
                              </tr>
                              <%
                                  }
                              %>
                              </tbody>
                          </table>
                          <%  
                              totalCost += (float)subInfo.get("deposit") / (1 - room_dis / 100);
                              
                              double grandTotal = totalCost * (1 - room_dis / 100);
                          %>
                          <div class="row">
                              <div class="col-lg-4 invoice-block pull-right">
                                  <ul class="unstyled amounts">
                                      <li><strong>Sub - Total amount :</strong> $ <%=String.format("%.2f", totalCost) %></li>
                                      <li><strong>Discount :</strong> <%=room_dis %>%</li>
                                      <li><strong>VAT :</strong> -----</li>
                                      <li><strong>Grand Total :</strong> $ <%=String.format("%.2f", grandTotal) %></li>
                                  </ul>
                              </div>
                          </div>
                          <div class="text-center invoice-btn">
                              <a class="btn btn-danger btn-lg" href='./background/sub_checkout_do.jsp?id=<%=sub_id %>'><i class="icon-check"></i> Check-out </a>
                              <a class="btn btn-info btn-lg" onclick="javascript:window.print();"><i class="icon-print"></i> Print </a>
                          </div>
                      </div>
                  </div>
              </section>
              <!-- invoice end-->
          </section>
      </section>
      <!--main content end-->
  </section>

    <!-- js placed at the end of the document so the pages load faster -->
    <script src="../Public/js/jquery.js"></script>
    <script src="../Public/js/bootstrap.min.js"></script>
    <script src="../Public/js/jquery.scrollTo.min.js"></script>
    <script src="../Public/js/jquery.nicescroll.js" type="text/javascript"></script>


    <!--common script for all pages-->
    <script src="../Public/js/common-scripts.js"></script>


  </body>
</html>
<%
    }
%>
